package sjy.dao;

import com.mysql.cj.jdbc.Driver;
import sjy.domain.User;


import java.sql.*;

public class ConnectMysql {
    public boolean ConnectMysql(User users) throws SQLException {
        String url = "jdbc:mysql://localhost:3306/imu_student?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8";
        String user = "root";
        String password = "111111";
        Driver driver =new Driver();
        DriverManager.registerDriver(driver);
        Connection conn =DriverManager.getConnection(url, user,password );
        String sql = "select * from user where name =";
        sql += " '"  + users.getName() + "' and password = '";
        sql += users.getPassword() + "'";
//        System.out.println(sql);
        Statement statement = conn.createStatement();
        ResultSet rows = statement.executeQuery(sql);
        boolean flag = false;
        while (rows.next()){
            flag = true;
        }
        statement.close();
        conn.close();
        return flag;
    }


}
